function QMSTouchScreen() {
  this.clickFlag = false;
  this.background = '#FFFFFF';
  this.highlight = '#0000FF';
  this.component = '';
}

QMSTouchScreen.prototype = {
  initialize: function() {
    var parentObj = this;

    $('.selection').click(function() {
	var id = $(this).attr('id');
	var name = $(this).html();
	$(this).css('background-color', parentObj.highlight);
	$.post('/touchscreen/create_request', {"id": id, "component": parentObj.component}, function(data){	    
	    eval("var obj = " + data + ";");
	    if(obj.status) {
		$('#dialog1').html('Requested Service:<br/><b> ' + name + '</b><br/><br/>Kindly collect your token and wait for your turn.');
	    } else {
		$('#dialog1').html('An error occurred while printing the token. Please try again.');
	    }
	    $('#dialog1').dialog( "open" );
	    $('.selection').css('background-color', parentObj.background);
	    setTimeout(function(){ $('#dialog1').dialog( "close" );},3000);
	    
	});	
    });    
  }  
};

var tshandler = new QMSTouchScreen();
$(document).ready(function() {  
    $("#dialog1").dialog({
	    autoOpen: false,
	    width: 300,
	    modal: true
    });     
    tshandler.initialize();
});    
